package com.theone.dagger2.use2;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.theone.dagger2.bean.PersonBean;
import com.theone.dagger2.R;
import com.theone.dagger2.bean.UserBean;

import javax.inject.Inject;


/**
 * TODO 局部单例
 *
 * 生成代码位置：build/generated/ap_generated_sources/debug/out/com/theone/dagger2
 */
public class MainActivity2_1 extends AppCompatActivity {

    @Inject
    UserBean mUser;

    @Inject
    UserBean mUser2;

    @Inject
    PersonBean mPerson;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        // DaggerDataComponent2.class 是生成的

        DaggerDataComponent2.create().injectMainActivity2_1(this);

        /*
         方法二
            DaggerDataComponent2.builder()
                .userModule(new UserModule())
                .personModule(new PersonModule())
                .build()
                .injectMainActivity(this);
         */

        TextView textView = findViewById(R.id.textview);
        textView.setText("User hashCode = "+mUser.hashCode()+" \n User2 hashCode = "+mUser2.hashCode()+"\n Person hashCode = "+mPerson.hashCode());

    }

    public void jump(View view) {
        startActivity(new Intent(this, MainActivity2_2.class));
    }

}